package com.stone.business.sbqxjl.action;

/**
 * <pre>
 * 设备缺陷记录
 * @author
 * </pre>
 */

import java.util.HashMap;
import java.util.List;

import com.stone.business.gzrwd.service.ZbjlCommonService;
import com.stone.business.sbqxjl.pojo.TSbqxjl;
import com.stone.sys.pojo.TDictionary;
import com.stone.sys.service.DictionaryService;
import com.stone.utils.StringUtils;

import frm.ssh.action.BaseListAction;
import frm.ssh.util.SpringUtil;

public class ddqxListAction extends BaseListAction {

	private static final long serialVersionUID = 3979577965804736350L;

	private ZbjlCommonService myService;
	
	public ZbjlCommonService getMyService() {
		return myService;
	}

	public void setMyService(ZbjlCommonService myService) {
		this.service = myService;
		this.myService = myService;
	}
	
    /** * 构造方法. */
    public ddqxListAction() {
        this.entityClass = TSbqxjl.class;
    }
    
	// 缺陷类别
	private List<TDictionary> qxlbList;
	
	/**
	 * 设置查询条件
	 */
	public HashMap<String, Object> setSearchCondition() {    
		String sql = ""; 
		String conditions ="";
		HashMap<String, Object> m = new HashMap<String, Object>();
		
	// 发现时间
	if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon2())) {
		conditions += " AND TO_CHAR(a.report_time,'yyyy-MM-dd') >= '"+super.getSearchBean().getCon2()+"'";
		
	}
	
	if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon3())) {
		conditions += " AND TO_CHAR(a.report_time,'yyyy-MM-dd') <= '"+super.getSearchBean().getCon3()+"'";
	
	}
	
	
	// 缺陷类别
	if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon7())) {
		conditions += " AND a.category = '"+super.getSearchBean().getCon7()+"'";
		
	}
	// 变电站 by wangtao add20120223
	if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon4())) {
		conditions += " AND get_bdzid(a.address) in (";
		StringBuffer buf= new StringBuffer(""); 
		String[] bdznames = ((String) super.getSearchBean().getCon5() == null? "" : super.getSearchBean().getCon5()).split(",");
		
		for (int i=0; i< bdznames.length; i++) { 
		  if (i!=0) buf.append(", "); 
		  buf.append("" + bdznames[i]+ ""); 
		 
		} 
		buf.append(")"); 
		conditions +=buf;

		
	}
	
		sql = "select a.cid as id,a.serial_no as serialno,TO_CHAR(a.report_time,'YYYY-MM-DD HH24:MI') as reporttime,TO_CHAR(a.resolve_time,'YYYY-MM-DD HH24:MI') as resolvetime,a.address as address," +
				"a.content as content,a.removed as remove,a.category as category,get_bdzname(a.address) as bdzname," +
				" case when b.id is null then '无' else b.xqbzname end as xqbzname,b.sbzp as filecount"
				+ " from dm_defect a left join tab_sbqxjl b"
				+ " on b.defectid = a.cid"+
				" where (notify_department = 1 or notify_department1 = 1) and (status = 'Q02' or status = 'Q01' or status = 'Q03') and (flag <> '1' or flag is null) ";
		sql=sql+conditions+" order by a.report_time Desc";
		m.put("pageflag", "sql");
		m.put("sql", sql);
		//m.put("clause", " order by a.report_time Desc");
		m.put("forward", "SUCCESS");
		
		DictionaryService dicService = (DictionaryService) SpringUtil.getInstance().getBean("dicService");
		
		// 缺陷类别
		qxlbList = dicService.findList("QXLB");
		
		return m;
		
	}

	public List<TDictionary> getQxlbList() {
		return qxlbList;
	}

	public void setQxlbList(List<TDictionary> qxlbList) {
		this.qxlbList = qxlbList;
	}



}
